import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// import frontRouter from './modules/front'
// import powerRouter from './modules/power'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: resolve => require.ensure([], () => resolve(require('@/views/redirect/index')), 'home')
      }
    ]
  },
  {
    path: '/login',
    component: resolve => require.ensure([], () => resolve(require('@/views/login/index')), 'home'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: resolve => require.ensure([], () => resolve(require('@/views/login/auth-redirect')), 'home'),
    hidden: true
  },
  {
    path: '/404',
    component: resolve => require.ensure([], () => resolve(require('@/views/error-page/404')), 'home'),
    hidden: true
  },
  {
    path: '/401',
    component: resolve => require.ensure([], () => resolve(require('@/views/error-page/401')), 'home'),
    hidden: true
  },
  {
    path: '/error',
    name: 'Error',
    component: resolve => require.ensure([], () => resolve(require('@/views/error-page')), 'home'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: resolve => require.ensure([], () => resolve(require('@/views/dashboard/index2')), 'home'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'home', affix: true }
      }
    ]
  },
  {
    path: '/camera/display',
    name: 'CameraDisplay',
    hidden: true,
    component: resolve => require.ensure([], () => resolve(require('@/views/control/cameraDisplay')), 'home'),
    meta: {
      title: '视频展示',
      noCache: true
    }
  },
  // 电气火灾
  {
    path: '/DataPageeq',
    name: 'DataPage',
    component: Layout,
    meta: {
      title: '数据查询',
      icon: 'data'
    },
    redirect: '/Data/LiveData',
    children: [
      {
        path: '/Data/LiveData',
        name: 'LiveData',
        component: resolve => require.ensure([], () => resolve(require('@/views/data/real')), 'data'),
        meta: {
          title: '实时数据',
        }
      },
      {
        path: '/Data/DataDisplay',
        name: 'SvgOne',
        component: resolve => require.ensure([], () => resolve(require('@/views/control/one')), 'Data'),
        meta: {
          title: '一次接线图'
        }
      },
    ]
  },
  {
    path: '/alarm',
    name: 'Alarm',
    component: Layout,
    meta: {
      title: '预警/告警管理',
      icon: 'alarm'
    },
    children: [
      {
        path: '/alarm/Info',
        name: '/InfoAlarm',
        // component: () => import('@/views/alarm/Accident'),
        component: resolve => require.ensure([], () => resolve(require('@/views/alarm/InfoAlarm')), 'alarm'),
        meta: {
          title: '预告警统计'
        }
      },
      // {
      //   path: '/alarm/accident',
      //   name: 'AccidentAlarm',
      //   // component: () => import('@/views/alarm/Accident'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Accident')), 'alarm'),
      //   meta: {
      //     title: '事故告警信息'
      //   }
      // },
      // {
      //   path: '/alarm/limit',
      //   name: 'LimitAlarm',
      //   // component: () => import('@/views/alarm/Limit'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Limit')), 'alarm'),
      //   meta: {
      //     title: '越限告警信息'
      //   }
      // },
      // {
      //   path: '/alarm/exception',
      //   name: 'ExceptionAlarm',
      //   // component: () => import('@/views/alarm/Exception'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Exception')), 'alarm'),
      //   meta: {
      //     title: '异常告警信息'
      //   }
      // },
      // {
      //   path: '/alarm/comm',
      //   name: 'CommAlarm',
      //   // component: () => import('@/views/alarm/Comm'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Comm')), 'alarm'),
      //   meta: {
      //     title: '通信告警信息'
      //   }
      // },
      // {
      //   path: '/alarm/unbalance',
      //   name: 'UnbalanceAlarm',
      //   // component: () => import('@/views/alarm/Unbalance'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Unbalance')), 'alarm'),
      //   meta: {
      //     title: '不平衡告警信息'
      //   }
      // },
      // {
      //   path: '/alarm/inhibition',
      //   name: 'InhibitionAlarm',
      //   // component: () => import('@/views/alarm/Inhibition'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Inhibition')), 'alarm'),
      //   meta: {
      //     title: '告警抑制信息'
      //   }
      // },
    ]
  },
  {
    path: '/History',
    name: 'HistoryPage',
    component: Layout,
    meta: {
      title: '历史数据分析',
      icon: 'data'
    },
    redirect: '/History',
    children: [
      {
        path: '/History',
        name: 'History',
        component: resolve => require.ensure([], () => resolve(require('@/views/data/real')), 'data'),
        meta: {
          title: '历史数据分析',
        }
      }
    ]
  },
  {
    path: '/device',
    name: 'Device',
    component: Layout,
    redirect: '/devices',
    meta: {
      title: '设备管理',
      icon: 'device-mng'
    },
    children: [
      {
        path: '/devices',
        name: 'Devices',
        // component: () => import('@/views/device/List'),
        component: resolve => require.ensure([], () => resolve(require('@/views/device/List')), 'device'),
        meta: {
          title: '设备信息',
        },
      },
      {
        path: '/device/:id/detail',
        name: 'DeviceDetail',
        hidden: true,
        // component: () => import('@/views/device/detail'),
        component: resolve => require.ensure([], () => resolve(require('@/views/device/detail')), 'device'),
        meta: {
          title: '设备信息'
        }
      },
      // {
      //   path: '/device/transfromer',
      //   name: 'Transformer',
      //   // component: () => import('@/views/device/transformer'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/device/transformer')), 'device'),
      //   meta: {
      //     title: '变压器系统'
      //   }
      // },
      // {
      //   path: '/device/repairorder',
      //   name: 'RepairOrder',
      //   // component: () => import('@/views/device/RepairOrder'),
      //   component: resolve => require.ensure([], () => resolve(require('@/views/device/RepairOrder')), 'device'),
      //   meta: {
      //     title: '设备维护日志',
      //   }
      // }
    ]
  },
]

/**
  * asyncRoutes
  *需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [
  {
    path: '/user',
    name: 'User',
    component: Layout,
    meta: {
      title: '用户管理',
      icon: 'user1'
    },
    redirect: '/user/list',
    children: [
      {
        path: '/user/list',
        name: 'Users',
        // component: () => import('@/views/user'),
        component: resolve => require.ensure([], () => resolve(require('@/views/user')), 'User'),
        meta: {
          title: '用户列表',
        }
      },
      {
        path: '/user/role',
        name: 'UserRole',
        // component: () => import('@/views/user/UserRole'),
        component: resolve => require.ensure([], () => resolve(require('@/views/user/UserRole')), 'User'),
        meta: {
          title: '角色列表',
        }
      },
      {
        path: '/user/privilege',
        name: 'Privilege',
        // component: () => import('@/views/user/Privilege'),
        component: resolve => require.ensure([], () => resolve(require('@/views/user/Privilege')), 'User'),
        meta: {
          title: '权限列表',
        }
      },
      {
        path: '/user/resource',
        name: 'Resouce',
        // component: () => import('@/views/user/Resouce'),
        component: resolve => require.ensure([], () => resolve(require('@/views/user/Resouce')), 'User'),
        meta: {
          title: '资源列表',
        }
      },
    ]
  },
  // {
  //   path: '/workorder',
  //   name: 'WorkorderList',
  //   component: Layout,
  //   redirect: '/process/list',
  //   meta: {
  //     title: '工单管理',
  //     icon: 'work'
  //   },
  //   children: [
  //     {
  //       path: '/process/:id/node',
  //       name: 'ProcessNode',
  //       // component: () => import('@/views/workorder/Node'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/Node')), 'workorder'),
  //       hidden: true,
  //       meta: {
  //         title: '设置节点'
  //       }
  //     },
  //     {
  //       path: '/process/list',
  //       name: 'Processes',
  //       // component: () => import('@/views/workorder/ProcessList'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/ProcessList')), 'workorder'),
  //       meta: {
  //         title: '流程列表'
  //       }
  //     },
  //     {
  //       path: '/workorders',
  //       name: 'Workorders',
  //       // component: () => import('@/views/workorder/List'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/List')), 'workorder'),
  //       meta: {
  //         title: '工单列表',
  //       }
  //     },
  //     {
  //       path: '/workorders/now',
  //       name: 'now',
  //       // component: () => import('@/views/workorder/ReakOrder'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/ReakOrder')), 'workorder'),
  //       meta: {
  //         title: '实时工单',
  //       }
  //     },
  //     {
  //       path: '/workorders/History',
  //       name: 'History',
  //       // component: () => import('@/views/workorder/History'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/History')), 'workorder'),
  //       meta: {
  //         title: '历史工单',
  //       }
  //     },
  //     {
  //       path: '/workorders/mine',
  //       name: 'Mine',
  //       // component: () => import('@/views/workorder/Mine'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/workorder/Mine')), 'workorder'),
  //       meta: {
  //         title: '我的任务'
  //       }
  //     },
  //   ]
  // },
  // {
  //   path: '/device',
  //   name: 'Device',
  //   component: Layout,
  //   redirect: '/devices',
  //   meta: {
  //     title: '设备管理',
  //     icon: 'device-mng'
  //   },
  //   children: [
  //     {
  //       path: '/devices',
  //       name: 'Devices',
  //       // component: () => import('@/views/device/List'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/device/List')), 'device'),
  //       meta: {
  //         title: '设备台账',
  //       },
  //     },
  //     {
  //       path: '/device/:id/detail',
  //       name: 'DeviceDetail',
  //       hidden: true,
  //       // component: () => import('@/views/device/detail'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/device/detail')), 'device'),
  //       meta: {
  //         title: '设备详情'
  //       }
  //     },
  //     {
  //       path: '/device/transfromer',
  //       name: 'Transformer',
  //       // component: () => import('@/views/device/transformer'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/device/transformer')), 'device'),
  //       meta: {
  //         title: '变压器系统'
  //       }
  //     },
  //     {
  //       path: '/device/repairorder',
  //       name: 'RepairOrder',
  //       // component: () => import('@/views/device/RepairOrder'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/device/RepairOrder')), 'device'),
  //       meta: {
  //         title: '设备维护日志',
  //       }
  //     }
  //   ]
  // },
  // {
  //   path: '/alarm',
  //   name: 'Alarm',
  //   component: Layout,
  //   meta: {
  //     title: '预警/告警管理',
  //     icon: 'alarm'
  //   },
  //   children: [
  //     {
  //       path: '/alarm/accident',
  //       name: 'AccidentAlarm',
  //       // component: () => import('@/views/alarm/Accident'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Accident')), 'alarm'),
  //       meta: {
  //         title: '事故告警信息'
  //       }
  //     },
  //     {
  //       path: '/alarm/limit',
  //       name: 'LimitAlarm',
  //       // component: () => import('@/views/alarm/Limit'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Limit')), 'alarm'),
  //       meta: {
  //         title: '越限告警信息'
  //       }
  //     },
  //     {
  //       path: '/alarm/exception',
  //       name: 'ExceptionAlarm',
  //       // component: () => import('@/views/alarm/Exception'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Exception')), 'alarm'),
  //       meta: {
  //         title: '异常告警信息'
  //       }
  //     },
  //     {
  //       path: '/alarm/comm',
  //       name: 'CommAlarm',
  //       // component: () => import('@/views/alarm/Comm'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Comm')), 'alarm'),
  //       meta: {
  //         title: '通信告警信息'
  //       }
  //     },
  //     {
  //       path: '/alarm/unbalance',
  //       name: 'UnbalanceAlarm',
  //       // component: () => import('@/views/alarm/Unbalance'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Unbalance')), 'alarm'),
  //       meta: {
  //         title: '不平衡告警信息'
  //       }
  //     },
  //     {
  //       path: '/alarm/inhibition',
  //       name: 'InhibitionAlarm',
  //       // component: () => import('@/views/alarm/Inhibition'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/alarm/Inhibition')), 'alarm'),
  //       meta: {
  //         title: '告警抑制信息'
  //       }
  //     },
  //   ]
  // },
  // {
  //   path: '/data',
  //   name: 'Data',
  //   component: Layout,
  //   redirect: '/data/real',
  //   meta: {
  //     title: '数据查询',
  //     icon: 'data'
  //   },
  //   children: [
  //     {
  //       path: '/data/real',
  //       name: 'RealData',
  //       // component: () => import('@/views/data/real'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/real')), 'data'),
  //       meta: {
  //         title: '实时数据'
  //       }
  //     },
  //     {
  //       path: '/data/history',
  //       name: 'HistoryData',
  //       // component: () => import('@/views/data/history'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/history')), 'data'),
  //       meta: {
  //         title: '历史数据'
  //       }
  //     },
  //     {
  //       path: '/data/manual',
  //       name: 'Manual',
  //       // component: () => import('@/views/data/manual'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/manual')), 'data'),
  //       meta: {
  //         title: '人工置数信息查询'
  //       }
  //     },
  //     {
  //       path: '/data/brand',
  //       name: 'Brand',
  //       // component: () => import('@/views/data/brand'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/brand')), 'data'),
  //       meta: {
  //         title: '置标识牌信息查询'
  //       }
  //     },
  //     {
  //       path: '/data/all',
  //       name: 'AllData',
  //       // component: () => import('@/views/data/AllData'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/AllData')), 'data'),
  //       meta: {
  //         title: '电能集抄'
  //       }
  //     },
  //     {
  //       path: '/data/allhis',
  //       name: 'AllDataHis',
  //       // component: () => import('@/views/data/AllDataHis'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/AllDataHis')), 'data'),
  //       meta: {
  //         title: '电能历史数据'
  //       }
  //     },
  //     {
  //       path: '/data/monthly',
  //       name: 'DataMonthly',
  //       // component: () => import('@/views/data/monthly'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/data/monthly')), 'data'),
  //       meta: {
  //         title: '月报列表'
  //       }
  //     }
  //   ]
  // },
  // {
  //   path: '/control',
  //   name: 'Control',
  //   component: Layout,
  //   redirect: '/control/svg',
  //   meta: {
  //     title: '实时运行监控',
  //     icon: 'control'
  //   },
  //   children: [
  //     {
  //       path: '/control/one',
  //       name: 'SvgOne',
  //       // component: () => import('@/views/control/one'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/control/one')), 'control'),
  //       meta: {
  //         title: '一次接线图'
  //       }
  //     },
  //     {
  //       path: '/control/dev',
  //       name: 'SvgDev',
  //       // component: () => import('@/views/control/dev'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/control/dev')), 'control'),
  //       meta: {
  //         title: '设备运行图'
  //       }
  //     },
  //     {
  //       path: '/control/comm',
  //       name: 'SvgComm',
  //       // component: () => import('@/views/control/comm'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/control/comm')), 'control'),
  //       meta: {
  //         title: '通讯检测图'
  //       }
  //     },
  //     {
  //       path: '/control/camera',
  //       name: 'Camera',
  //       // component: () => import('@/views/control/camera'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/control/camera')), 'control'),
  //       meta: {
  //         title: '视频监控'
  //       }
  //     },
  //   ]
  // },
  // {
  //   path: '/company',
  //   name: 'Company',
  //   component: Layout,
  //   meta: {
  //     title: '项目管理',
  //     icon: 'conpany'
  //   },
  //   redirect: '/company/list',
  //   children: [
  //     {
  //       path: '/company/list',
  //       name: 'CompanyList',
  //       // component: () => import('@/views/company'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/company')), 'control'),
  //       meta: {
  //         title: '项目列表',
  //       }
  //     },
  //     // {
  //     //   path: '/company/staff',
  //     //   name: 'Staff',
  //     //   component: () => import('@/views/company/staff'),
  //     //   meta: {
  //     //     title: '员工列表',
  //     //   }
  //     // },
  //     {
  //       path: '/company/station',
  //       name: 'Station',
  //       // component: () => import('@/views/company/station'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/company/station')), 'control'),
  //       meta: {
  //         title: '站点列表'
  //       }
  //     },
  //     {
  //       path: '/company/contract',
  //       name: 'Contract',
  //       // component: () => import('@/views/company/contract'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/company/contract')), 'control'),
  //       meta: {
  //         title: '合同列表'
  //       }
  //     },
  //     {
  //       path: '/company/contract/:id/maintain',
  //       name: 'Maintain',
  //       hidden: true,
  //       // component: () => import('@/views/company/maintain'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/company/maintain')), 'control'),
  //       meta: {
  //         title: '维护项目',
  //         noCache: true,
  //       }
  //     },
  //     {
  //       path: '/company/map',
  //       name: 'StationMap',
  //       // component: () => import('@/views/company/stationMap'),
  //       component: resolve => require.ensure([], () => resolve(require('@/views/company/stationMap')), 'control'),
  //       meta: {
  //         title: '站点地图'
  //       }
  //     }
  //   ]
  // },
  // frontRouter,
  // ...powerRouter,
  // {
  //   path: '/abuttonrepair',
  //   name: 'abuttonrepair',
  //   component: Layout,
  //   meta: {
  //     title: '报修列表',
  //     icon: 'conpany'
  //   },
  //   children: [
  //     {
  //       path: "/abuttonrepair",
  //       name: "Services",
  //       component: resolve => require.ensure([], () => resolve(require('@/views/serv/index')), 'abuttonrepair'),
  //       meta: {
  //         title: "报修列表",
  //       }
  //     }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由器
}

export default router
